<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="com.uc.training.smadmin.ord.dao.OrderGoodsDao">
    <!--通过商品属性id获取待支付的商品属性数量-->
	<select id="getUnPayGoodsPropertyCountByPropertyId" parameterClass="Long" resultClass="Integer">
		select
		COUNT(1)
		from t_ord_order o,t_ord_order_goods g
		where o.id = g.order_id AND o.`status` = 1 AND g.goods_property_id = #propertyId#
	</select>

	<!-- 根据对象的不为null的值作为条件进行查找 -->
	<select id="getOrderGoodsById" resultClass="com.uc.training.smadmin.ord.model.OrderGoods" parameterClass="Integer">
		 SELECT
		 s.id AS id,
		 s.order_id AS orderId,
		 s.goods_id AS goodsId,
		 s.goods_property_id AS goodsPropertyId,
		 s.goods_num AS goodsNum,
		 s.comment_status AS commentStatus,
		 s.sale_price AS salePrice,
		 s.discount_price AS discountPrice,
		 s.pay_price AS payPrice,
		 s.create_emp AS createEmp,
		 s.create_time AS createTime,
		 s.modify_emp AS modifyEmp,
		 s.modify_time AS modifyTime
		 FROM t_ord_order_goods s		 WHERE s.order_id=#id#
	</select>

    <!--通过订单商品表ID获取订单信息-->
	<select id="getOrdeByOrdGoodsId" resultClass="com.uc.training.smadmin.ord.model.Order">
		select
		c1.order_num as orderNum
		FROM t_ord_order_goods c
		LEFT JOIN t_ord_order c1
		ON
		c1.id = c.order_id
		where
		c.id = #ordGoodsId#
	</select>
	<sql id="where_query">

		 <isNotEmpty property="id" prepend="and">
			 s.id = #id#
		 </isNotEmpty>
		 <isNotEmpty property="orderId" prepend="and">
			 s.order_id = #orderId#
		 </isNotEmpty>
		 <isNotEmpty property="goodsId" prepend="and">
			 s.goods_id = #goodsId#
		 </isNotEmpty>
		 <isNotEmpty property="goodsPropertyId" prepend="and">
			 s.goods_property_id = #goodsPropertyId#
		 </isNotEmpty>
		 <isNotEmpty property="goodsNum" prepend="and">
			 s.goods_num = #goodsNum#
		 </isNotEmpty>
		 <isNotEmpty property="salePrice" prepend="and">
			 s.sale_price = #salePrice#
		 </isNotEmpty>
		 <isNotEmpty property="discountPrice" prepend="and">
			 s.discount_price = #discountPrice#
		 </isNotEmpty>
		 <isNotEmpty property="payPrice" prepend="and">
			 s.pay_price = #payPrice#
		 </isNotEmpty>
		 <isNotEmpty property="createEmp" prepend="and">
			 s.create_emp = #createEmp#
		 </isNotEmpty>
		 <isNotEmpty property="createTime" prepend="and">
			 s.create_time = #createTime#
		 </isNotEmpty>
		 <isNotEmpty property="modifyEmp" prepend="and">
			 s.modify_emp = #modifyEmp#
		 </isNotEmpty>
		 <isNotEmpty property="modifyTime" prepend="and">
			 s.modify_time = #modifyTime#
		 </isNotEmpty>
	</sql>

	<!-- 列表查询 -->
	<select id="queryOrderGoodsList" resultClass="com.uc.training.smadmin.ord.model.OrderGoods">
		 SELECT
		 s.order_id AS orderId,
		 s.goods_id AS goodsId,
		 s.goods_property_id AS goodsPropertyId,
		 s.goods_num AS goodsNum,
		 s.sale_price AS salePrice,
		 s.discount_price AS discountPrice,
		 s.pay_price AS payPrice,
		 s.create_emp AS createEmp,
		 s.create_time AS createTime,
		 s.modify_emp AS modifyEmp,
		 s.modify_time AS modifyTime
		 FROM t_ord_order_goods s
		 WHERE 1=1
		 <!--  <isEmpty property="queryType"> order by s.id DESC </isEmpty>  -->
		 <!--  <isNotEmpty property="rows" prepend=" "> limit #start#,#rows#</isNotEmpty>/>  -->
	</select>

	<!-- 查找数据总记录数 -->
	<select id="queryOrderGoodsCount" resultClass="java.lang.Integer" parameterClass="com.uc.training.smadmin.ord.model.OrderGoods">
		 SELECT count(1)
		 FROM t_ord_order_goods s
		 WHERE 1=1
	</select>

	<!-- 插入 -->
	<insert id="insertOrderGoods" parameterClass="com.uc.training.smadmin.ord.model.OrderGoods">
		 insert into t_ord_order_goods
			 (order_id, goods_id, goods_property_id, goods_num,comment_status, sale_price, discount_price, pay_price,create_time)
		values (#orderId#,#goodsId#,#goodsPropertyId#,#goodsNum#,1,#salePrice#,#discountPrice#,#payPrice#,now())
	<selectKey keyProperty="id">
		select LAST_INSERT_ID() AS id
	</selectKey>
	</insert>

	<!-- 通过主键更新 -->
	<update id="updateOrderGoodsById" parameterClass="com.uc.training.smadmin.ord.model.OrderGoods">
		 update t_ord_order_goods set
		id = #id#, order_id = #orderId#, goods_id = #goodsId#, goods_property_id = #goodsPropertyId#, goods_num = #goodsNum#, sale_price = #salePrice#, discount_price = #discountPrice#, pay_price = #payPrice#, create_emp = #createEmp#, create_time = #createTime#, modify_emp = #modifyEmp#, modify_time = #modifyTime#
		where id=#id#
		</update>

	<update id="updateOrderGoodsCommentStatusById" parameterClass="com.uc.training.smadmin.ord.vo.OrdOrderGoodsVo">
		 update t_ord_order_goods set
		 comment_status = #commentStatus#
		 where id=#id#
		</update>

</sqlMap>